package com.wasp.collector.service.akka;

import java.util.HashMap;
import java.util.Map;

import akka.actor.AbstractActor;
import akka.japi.pf.ReceiveBuilder;
import scala.PartialFunction;
import scala.runtime.BoxedUnit;

public class DefaultWorker extends AbstractActor {

	Map<String, Integer> cache = new HashMap<String, Integer>();

	@Override
	public PartialFunction<Object, BoxedUnit> receive() {
		System.out.println("************DefaultWorker");
		return ReceiveBuilder.match(String.class, word -> {
			Integer length = cache.get(word);
			if (length == null) {
				length = word.length();
				cache.put(word, length);
			}
			sender().tell(length, self());
		}).build();
	}
}
